package svc

import (
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"gozerogateway/rpc/model/svcmodel"
	"gozerogateway/rpc/svc/internal/config"
)

type ServiceContext struct {
	Config config.Config

	SvcModel              svcmodel.GatewayServiceInfoModel
	SvcAccessControlModel svcmodel.GatewayServiceAccessControlModel
	SvcGrpcModel          svcmodel.GatewayServiceGrpcRuleModel
	SvcHttpModel          svcmodel.GatewayServiceHttpRuleModel
	SvcTcpModel           svcmodel.GatewayServiceTcpRuleModel
	SvcLoadBalanceModel   svcmodel.GatewayServiceLoadBalanceModel
}

func NewServiceContext(c config.Config) *ServiceContext {

	sqlConn := sqlx.NewMysql(c.Mysql.Datasource)
	return &ServiceContext{
		Config: c,

		SvcModel:              svcmodel.NewGatewayServiceInfoModel(sqlConn, c.Cache),
		SvcAccessControlModel: svcmodel.NewGatewayServiceAccessControlModel(sqlConn, c.Cache),
		SvcGrpcModel:          svcmodel.NewGatewayServiceGrpcRuleModel(sqlConn, c.Cache),
		SvcHttpModel:          svcmodel.NewGatewayServiceHttpRuleModel(sqlConn, c.Cache),
		SvcTcpModel:           svcmodel.NewGatewayServiceTcpRuleModel(sqlConn, c.Cache),
		SvcLoadBalanceModel:   svcmodel.NewGatewayServiceLoadBalanceModel(sqlConn, c.Cache),
	}
}
